import { API_LIST } from '../../../Api/Api'
import { commonTableList } from '../Common/common'
import { AddDataButton, ModDataButton, DelDataButton, OpenThrTouter, ExamineButton } from '../Common/options'

export const InspectionDetails = async ({ OptionsEvent, oneData, Permission, actionRef, type }) => {
    const mapping = {
        quality: {
            get: API_LIST()['getQualityDetail'],
            added: 'posQualityDetail',
            modify: `putQualityDetail`,
            del: 'QualityDetail',
            put: 'putQualityDetailSubmit',
            initUuid: 'qualityUuid',
            date: 'qualityDetailDate',
            text: '质量',
        },
        security: {
            get: API_LIST()['getSecurityDetail'],
            added: 'posSecurityDetail',
            modify: `putSecurityDetail`,
            del: 'SecurityDetail',
            put: 'putSecurityDetailSubmit',
            initUuid: 'securityUuid',
            date: 'securityDetailDate',
            text: '安全',
        },
    }

    const { text, get, added, modify, del, put, initUuid, date } = mapping[type]

    const data = {
        hideInSearch: true,
        pageSize: 10,
        initialValues: { [initUuid]: oneData?.uuid },
        params: { pageIndex: 1, [initUuid]: oneData.uuid },
        get,
        added,
        modify,
        options: [
            oneData.auditStatus === 1 && (
                <AddDataButton OptionsEvent={OptionsEvent} type="primary" icon="add" title="新增整改信息" />
            ),
        ],
        columns: [
            // 名称 描述 日期
            commonTableList.uuid,
            {
                dataIndex: initUuid,
                title: initUuid,
                valueType: 'hidden',
                hideInTable: true,
            },
            { ...commonTableList.tableName, title: '整改主题' },
            {
                dataIndex: 'description',
                title: '整改描述',
                valueType: 'input',
                rules: true,
                ellipsis: true,
                width: 250,
            },
            {
                dataIndex: date,
                title: '整改日期',
                valueType: 'Date',
                rules: true,
                width: 250,
            },
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 300,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    const { uuid, handling } = record
                    return [
                        <OpenThrTouter
                            key="thrOne"
                            title="附件详情"
                            twoTitle="整改详情信息"
                            modal="TableList"
                            width={'80vw'}
                            OptionsEvent={OptionsEvent}
                            other={{
                                page: 'InspectionDetailAttachment',
                                actionRef,
                                Permission,
                                twoData: record,
                                type,
                            }}
                        />,

                        handling === 1 && (
                            <ExamineButton
                                key="one"
                                title="提交待审"
                                data={{
                                    actionRef,
                                    OptionsEvent,
                                    url: put,
                                    smallTitle: `提交${text}巡检`,
                                }}
                                options={[
                                    { title: '接受', type: 'primary', emit: { path: [uuid] } },
                                    { title: '取消', type: 'link', emit: 'off' },
                                ]}
                            />
                        ),
                        oneData.auditStatus === 1 && handling === 1 && (
                            <ModDataButton OptionsEvent={OptionsEvent} key="modify" title="修改" data={record} />
                        ),
                        oneData.auditStatus === 1 && handling === 1 && (
                            <DelDataButton OptionsEvent={OptionsEvent} key="del" title="删除" url={del} uuid={uuid} />
                        ),
                    ]
                },
            },
        ],
    }

    return data
}
